function sd = gpsw2serial(w,d)
%
%SD = gpsw2serial(GPSW)
%SD = gpsw2serial(W,D) 
%
% Computes the MATLAB serial date SD from the vector of complete GPS dates
% GPSW or the vectors of weeks W and days D.
% The vector GPSW can be either a vector of integer numbers or a string 
% vector. If two input vectors are provided, they must be integers (if no 
% integers are provided, the corresponding rounds to the nearest integers
% towards zero are considered).
%
% See also date2gpsw, MJD2frac, frac2MJD, serial2frac, frac2serial,
% MJD2serial, serial2YMD. 

% G. Teza, 2008, 2021

if nargin == 1
    if isnumeric(w)
        w = num2str(fix(w(:)));
    end
    I = strcmpi(w(:,1),'N');
    sI = sum(I);
    if sI > 0
       w(I,:) = num2str(zeros(sI,size(w,2))); 
    end
    d = str2num(w(:,end));
    w = str2num(w(:,1:end-1));
else
    w = fix(w(:));
    d = fix(d(:));
    I = isnan(w);
    sI = sum(I);
    if sI > 0
       w(I,:) = zeros(sI,1);
       d(I,:) = zeros(sI,1);
    end
end

dater = datenum(1980,1,6);       % reference (first GPS week)

sd = dater+w*7+d;

if sI > 0
    sd(I) = NaN;
end